<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin-top: 20px;
        }

        .demo1{
            height: 50px;
            background-color: skyblue;
        }

        .box1{
            padding: 5px;
            background-color: skyblue;
        }
        .box2{
            padding: 5px;
            background-color: orange;
        }

        .list{
            width: 200px;
            height: 200px;
            background-color: peru;
            overflow: auto;
        }
        li{
            height: 100px;
        }
    </style>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <!--vue共有6种事件修饰符，只有前三种常用-->
        <h1>欢迎来到{{name}}学习</h1>
        <!--.prevent 阻止默认事件（阻止跳转）-->
        <a href="https://www.bilibili.com" @click.prevent="showInfo">点我提示信息</a>

        <!--.stop 阻止事件冒泡-->
        <div class="demo1" @click="showInfo">
            <button @click.stop="showInfo">点我提示信息</button>
        </div>

        <div class="demo1" @click="showInfo">
            <!--阻止冒泡+阻止默认事件-->
            <a href="https://www.baidu.com" @click.stop.prevent="showInfo">点我提示信息</a>
        </div>

        <!--.once事件只触发一次-->
        <button @click.once="showInfo">点我提示信息</button>

        <!--.capture使用事件的捕获模式，即在捕获阶段处理事件。js事件默认先捕获再冒泡，在冒泡时处理事件，捕获是从外往内，冒泡是从内往外-->
        <div class="box1" @click.capture="showMsg(1)">
            div1
            <div class="box2" @click="showMsg(2)">
                div2
            </div>
        </div>

        <!--.self 是有event.target是当前操作的元素时才触发事件，本实例冒泡到div时不会触发事件-->
        <div class="demo1" @click.self="showInfo">
            <button @click="showInfo">点我提示信息</button>
        </div>

        <!--.passive事件的默认行为立即执行，无需等事件回调执行完毕-->
        <ul @wheel.passive="demo" class="list">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false

        let vm = new Vue({
            el: "#root", 
            data: {
                name: "sgg",
                address: "bj"
            },
            methods:{
                showInfo(e){
                    //e.stopPropagation() //js阻止冒泡
                    alert('同学你好！')
                },
                showMsg(msg) {
                    console.log(msg)
                },
                demo(){
                    //默认顺序：滚动滚轮->执行demo函数->进度条滚动
                    //加passive之后：滚动滚轮->进度条滚动->执行demo函数
                    for (let i = 0; i < 10000; i++) {
                        console.log('#')
                    }
                    console.log('累坏了')
                }
            }
        })

    </script>
</body>
</html>